package com.hopedove.workshop.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.hopedove.workshop.R
import com.hopedove.workshop.data.pojo.ObservableRecordItem
import com.hopedove.workshop.databinding.WorkshopRunningSituationRecordListItemBinding

class RunningSituationRecordAdapter : RecyclerView.Adapter<RunningSituationRecordAdapter.VH>() {
    private val dataList = mutableListOf<ObservableRecordItem>()


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        val binding: WorkshopRunningSituationRecordListItemBinding = DataBindingUtil.inflate(
            LayoutInflater.from(parent.context),
            R.layout.workshop_running_situation_record_list_item,
            parent,
            false
        )
        return VH(binding)
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        val item = dataList[position]
        item.planTypeSelection.set(item.planTypes.indexOf("大生产"))
        holder.binding.item = item
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    fun setData(list: List<ObservableRecordItem>) {
        dataList.clear()
        dataList.addAll(list)
        notifyDataSetChanged()
    }

    class VH(val binding: WorkshopRunningSituationRecordListItemBinding) :
        RecyclerView.ViewHolder(binding.root) {

    }
}

